﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Visa.DB;
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System.Drawing;

namespace Visa.Service.Export
{
    public class ExportEmail
    {

        public void ExportProductsToXlsx(string filePath, IList<VisaRe> products)
        {
            var newFile = new FileInfo(filePath);
            // ok, we can run the real code of the sample now
            using (var xlPackage = new ExcelPackage(newFile))
            {
                // uncomment this line if you want the XML written out to the outputDir
                //xlPackage.DebugMode = true; 

                // get handle to the existing worksheet
                var worksheet = xlPackage.Workbook.Worksheets.Add("Danh Sách Khách Hàng");
                //Create Headers and format them 
                var properties = new string[]
                {
                    "Họ và tên",
                    "Quốc tịch",
                    "Điện thoại",
                    "Email",
                    "Cần tu vấn đến nước",
                    "Nội dung yêu cầu",
                    "Ngày tạo",
                    "Trạng thái phản hồi",
                    
                };
                for (int i = 0; i < properties.Length; i++)
                {
                    worksheet.Cells[1, i + 1].Value = properties[i];
                    worksheet.Cells[1, i + 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
                    worksheet.Cells[1, i + 1].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
                    worksheet.Cells[1, i + 1].Style.Font.Bold = true;
                }


                int row = 2;
                foreach (var p in products)
                {
                    string Tts = string.Empty;

                    if (p.Status == false) Tts = "Chưa gởi mail phản hồi";
                    else Tts = "Đã gởi mail phản hồi";

                    int col = 1;

                    worksheet.Cells[row, col].Value = p.HoTen;
                    col++;

                    worksheet.Cells[row, col].Value = p.Quoctich;
                    col++;

                    worksheet.Cells[row, col].Value = p.Dt;
                    col++;

                    worksheet.Cells[row, col].Value = p.Email;
                    col++;

                    worksheet.Cells[row, col].Value = p.visadencacnuoc;
                    col++;

                    worksheet.Cells[row, col].Value = p.NoiDung;
                    col++;

                    worksheet.Cells[row, col].Value = string.Format("{0:dd/MM/yyyy}", p.DateCreate);
                    col++;

                    worksheet.Cells[row, col].Value = Tts;
                    col++;

                    row++;
                }
                // we had better add some document properties to the spreadsheet 

                // set some core property values
                xlPackage.Workbook.Properties.Title = "Danh Sách Đăng ký tư vấn Visa";
                xlPackage.Workbook.Properties.Author = "Lê Tấn Mạnh - Programmer";
                xlPackage.Workbook.Properties.Subject = "Danh Sách Đăng ký tư vấn Visa";
                xlPackage.Workbook.Properties.Keywords = "Danh Sách Đăng ký tư vấn Visa";
                xlPackage.Workbook.Properties.Category = "Tư vấn visa";
                xlPackage.Workbook.Properties.Comments = "Danh Sách Đăng ký tư vấn Visa";

                // set some extended property values
                xlPackage.Workbook.Properties.Company = "Phú Thịnh";
                //xlPackage.Workbook.Properties.HyperlinkBase = new Uri("www.maymayquanglong.com");

                // save the new spreadsheet
                xlPackage.Save();
            }
        }

        public void ExportEmailsToXlsx(string filePath, IList<EmailResgedit> products)
        {
            var newFile = new FileInfo(filePath);
            // ok, we can run the real code of the sample now
            using (var xlPackage = new ExcelPackage(newFile))
            {
                // uncomment this line if you want the XML written out to the outputDir
                //xlPackage.DebugMode = true; 

                // get handle to the existing worksheet
                var worksheet = xlPackage.Workbook.Worksheets.Add("Danh Email");
                //Create Headers and format them 
                var properties = new string[]
                {
                    "Email",
                    "Ngày tạo",
                    
                };
                for (int i = 0; i < properties.Length; i++)
                {
                    worksheet.Cells[1, i + 1].Value = properties[i];
                    worksheet.Cells[1, i + 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
                    worksheet.Cells[1, i + 1].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
                    worksheet.Cells[1, i + 1].Style.Font.Bold = true;
                }


                int row = 2;
                foreach (var p in products)
                {

                    int col = 1;

                    worksheet.Cells[row, col].Value = p.Email;
                    col++;

                    worksheet.Cells[row, col].Value = string.Format("{0:dd/MM/yyyy}", p.DateCreate);
                    col++;

                    row++;
                }
                // we had better add some document properties to the spreadsheet 

                // set some core property values
                xlPackage.Workbook.Properties.Title = "Danh Sách Đăng ký Email";
                xlPackage.Workbook.Properties.Author = "Lê Tấn Mạnh - Programmer";
                xlPackage.Workbook.Properties.Subject = "Danh Sách Đăng ký Email";
                xlPackage.Workbook.Properties.Keywords = "Danh Sách Đăng ký Email";
                xlPackage.Workbook.Properties.Category = "Tư vấn visa";
                xlPackage.Workbook.Properties.Comments = "Danh Sách Đăng ký Email";

                // set some extended property values
                xlPackage.Workbook.Properties.Company = "Phú Thịnh";
                //xlPackage.Workbook.Properties.HyperlinkBase = new Uri("www.maymayquanglong.com");

                // save the new spreadsheet
                xlPackage.Save();
            }
        }
    }
}
